home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir24 / paket61.zip / MAN07@.EXE / MAN07.DOC < prev   
Text File  |  1994-08-15  |  91KB  |  2,465 lines

  1. PART VII - SCRIPT PROCESSING
  2. Overview
  3.    paKet includes a simple Script processing facility. The key word there
  4.    is "simple".  Script is a special language that paKet interprets,
  5.    allowing it to process a pre-written set of commands.  The concept is
  6.    the same as the BATCH facility in DOS where we can store a sequence of
  7.    DOS commands in a BAT file.
  8.  
  9.    A Script file contains one or more Script commands and usually has a
  10.    .SCP extension.  A Script is written in plain, ASCII text so you can use
  11.    any text editor to create or modify a Script file.
  12.  
  13.    It is not a complex language and it is certainly NOT a sophisticated
  14.    compiler.  The degree of error checking is not to be even compared to a
  15.    formal language compiler or assembler. I am relying on you to check out
  16.    your own Scripts and get the syntax correct.  If paKet detects something
  17.    strange it usually gives you enough information to help fix the problem
  18.    but occasionally it might just abort the Script where the problem is
  19.    detected.
  20.  
  21.    In practice it is not as bad as it sounds.   Most Script commands are
  22.    rather simple, so any problems are usually pretty obvious when they
  23.    occur.  Start out with some simple Scripts, to get the feel of it and
  24.    then you can develop more complex Scripts as you gain experience.  Many
  25.    paKet users have written Scripts without problems so I am sure you too
  26.    can join the ranks of successful paKet Script-writers.
  27.  
  28.    The Script facility should be sufficiently flexible to allow a variety
  29.    of operations, given a little imagination.  So if you do develop a
  30.    "good" Script file of your own, why not spread it around?  Broadcast it
  31.    to other users (I suggest a Bulletin addressed to PAKET rather than to
  32.    ALL would attract the attention of paKet users). I would appreciate it
  33.    if you could let me have a copy too, in case I miss your Bulletin.
  34.  
  35.    In this section of the Manual, we will be looking at some examples in a
  36.    Tutorial format to see what can be done with Scripts and to demonstrate
  37.    the syntax required.  You might like to have a look at these and then
  38.    with the ideas offered here you can go create some of your own.  Or even
  39.    easier, take one that NEARLY does what you want and alter it to suit. It
  40.    doesn't matter, you might not even use Scripts at all, but I am sure you
  41.    will find it challenging and fun, even creative. At least give it a try.
  42.  
  43.    Various Script commands will be introduced as we examine the sample
  44.    Scripts.  And there is a full command reference at the end of this
  45.    section of the Manual.
  46.  
  47.    A final word, before we get into the detail... it is probably obvious to
  48.    you by now but just in case, let me state quite clearly:  you do NOT
  49.    need to use Scripts if you don't want to.  It is NOT necessary to even
  50.    read this section of the Manual.  This is one of the more advanced
  51.    features of paKet so if you feel a bit threatened or confused by all
  52.    this talk of Scripts and Programming, just take a Valium and skip to
  53.    another part of the Manual.
  54.  
  55.                                Page 241
  56.  
  57. Running a Script File.
  58.    Press <Alt-S> to commence processing a Script you have available.
  59.  
  60.    A Directory Window will appear to help you select the wanted Script.
  61.    Highlight the desired Script filename (selecting another directory if
  62.    necessary) and press <Enter>. paKet will load and run that Script file.
  63.  
  64.    I recommend you keep all your Scripts in their own directory.  So when
  65.    the Directory Window appears, it will be easy to find and select the
  66.    Script you want.  It will be easier to manage too if you use the .SCP
  67.    extension for all your Scripts as paKet recognises this by default.
  68.  
  69.    The word "SCRIPT" will be displayed in the Status Window to the left of
  70.    the time display while the Script is running.   When the Script has
  71.    completed, the indicator in the Status Window will disappear and you
  72.    will be returned to normal communications.
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.                                Page 242
  112.  
  113. Script Tutorial - the S command
  114.  
  115.    To start with, let's look at a very simple Script:
  116.  
  117.          S MCON OFF
  118.          S CONOK ON
  119.  
  120.    In this section of the Manual I will indent the sample Scripts to
  121.    help separate the Script from my comments.  But when you are writing
  122.    your own Script, begin your Script commands in the first character
  123.    position of the line.
  124.  
  125.    This first Script file consists of just two lines, two Send commands.
  126.    Yes, the "S" is a Script command to "Send" the rest of that line to the
  127.    TNC.
  128.  
  129.    Most Script commands are single letter commands.  In the case of the S
  130.    command there is one parameter - that is the string which occupies the
  131.    rest of the line, starting from the first non-blank character.  Oh, I
  132.    should mention too that the Script commands may be typed in either
  133.    upper or lower case, so the Send command can be "S" or "s".
  134.  
  135.    When you run a Script, paKet will always start at the top, the first
  136.    line.  In this example, paKet will:
  137.  
  138.       - process that first Send command by sending the text "MCON OFF" to
  139.         the TNC.  It will automatically generate and send <Enter> at the
  140.         end of each Send line.
  141.  
  142.       - it will drop down to the next line.  This is another Send command
  143.         so the text "CONOK ON" will be sent to the TNC, followed by the
  144.         <Enter>.
  145.  
  146.       - as there are no more lines in the Script,  paKet will terminate
  147.         Script processing and return to normal communications mode.
  148.  
  149.  
  150.    That's not too hard now, is it?
  151.  
  152.  
  153.   Review
  154.    In this part:
  155.       We introduced the S command.
  156.  
  157.    This command:
  158.       The S command is used to Send text to the TNC.
  159.  
  160.    The syntax required:
  161.       S text
  162.     eg:
  163.       S CONVERSE
  164.       s Hello. My name is Tony.
  165.  
  166.  
  167.                                Page 243
  168.  
  169.  Practical exercise
  170.    OK, that's enough theory to get us going.  You already have enough
  171.    information to create and run a Script!   So, let's try a practical
  172.    exercise.
  173.  
  174.    We are going to create a Script file, then we are going to run it.
  175.  
  176.    Before we start we need to establish a few prerequisites:
  177.       I am assuming here that you have a text editor available and that
  178.       you know how to use it.
  179.  
  180.       And I am assuming you have configured your paKet system so there is
  181.       a Scripts directory somewhere on your disk.  If you have not yet
  182.       done that, press <F9> now to get the DOS prompt and Make a new
  183.       SCRIPTS directory.  Then as we continue with this Tutorial, the new
  184.       Scripts you create can go into that new directory.
  185.  
  186.       Check your Directories and Files Configuration (<Alt-Z> then 8) to
  187.       verify you have specified that path as your Scripts directory.
  188.  
  189.  
  190.    Now, using your text editor, create a new file in your Scripts
  191.    directory (use paKet's <Alt-E> command to call up your editor).  Name
  192.    it FIRST.SCP and type in the two lines of S commands as shown in the
  193.    example above.  Don't forget it is better if you commence typing these
  194.    commands in column 1.  Save the file and return to paKet.
  195.  
  196.    You have created your first Script!
  197.  
  198.    To run this Script, press <Alt-S> and you will see paKet's Directory
  199.    Window pop up.  If that is not showing your Scripts Directory, change
  200.    to that directory before continuing. (Normally paKet will display the
  201.    directory you used last time you ran a Script, but if this is the first
  202.    time, you might have to go find it yourself).
  203.  
  204.    Now that we have your SCRIPTS directory on the screen you should see
  205.    your file FIRST.SCP in that directory.  To run that Script, all you
  206.    have to do is select that file.  That is, move the highlight bar to
  207.    that file and press <Enter>.
  208.  
  209.    paKet will load and run that Script and you will see the two commands
  210.    appear on the screen as they are sent to the TNC and you will probably
  211.    see the TNC's responses.
  212.  
  213.    When that is finished you are back in paKet's normal communications
  214.    mode.   Easy huh?
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.                                Page 244
  224.  
  225. Script Tutorial - the B and D commands
  226.  
  227.    When you ran that first Script you might have noticed a couple of
  228.    problems.
  229.  
  230.    Firstly, we are sending some commands to the TNC, but what if the TNC
  231.    was not in Command Mode to start with?  if we were unlucky we could be
  232.    sending "MCON OFF" etc to the radio for transmission and the whole
  233.    world will be watching our mistake!
  234.  
  235.    So it is a good technique, when planning to send a TNC command, to
  236.    ensure our TNC is in Command Mode to start with.  If we were doing this
  237.    manually we would type <Alt-B> at the keyboard to send a BREAK code to
  238.    the TNC.  In a Script, we can use the "B" command to do the same thing.
  239.  
  240.    So let's add the following line to the beginning of our Script:
  241.  
  242.          B
  243.  
  244.    Just a single character on that line.  That's all we need here because
  245.    the B command has no parameters.
  246.  
  247.    You will notice when running that Script, that paKet will send the
  248.    first command (MCON OFF) followed almost immediately by the second
  249.    command.  This is OK and the TNC will accept our second command even
  250.    though it has not yet had time to process the first one.  But we will
  251.    see our second command appear on the screen before we see the TNC's
  252.    response to the first one.  It does not look nice and tidy on the
  253.    screen - it's out of sequence.
  254.  
  255.    With just two Send commands it probably doesn't matter too much... we
  256.    could cope with that, even if it doesn't look too good.  But if we had
  257.    ten or twenty or more commands to send, I think it would be worth the
  258.    trouble to add some delays to our Script.
  259.  
  260.    One way to add a delay is the "D" command.  This command will delay for
  261.    a specified number of seconds. So if we add:
  262.  
  263.            D 3
  264.  
  265.    to our Script after each of the commands, paKet would delay for 3
  266.    seconds before proceeding to the next line.  That 3 second delay should
  267.    be sufficient time for our TNC to process the previous command and send
  268.    its acknowledgement to paKet's display.
  269.  
  270.    So our first Script would now look something like:
  271.  
  272.          B
  273.          D 3
  274.          S MCON OFF
  275.          D 3
  276.          S CONOK ON
  277.  
  278.  
  279.                                Page 245
  280.  
  281.    Now, our Script will issue a BREAK code to the TNC to ensure we are in
  282.    Command Mode and delay for 3 seconds to give the TNC time to do that.
  283.    Then after sending that first command it will wait for 3 seconds before
  284.    sending the second command.  That is an improvement on our first
  285.    attempt, although it takes longer to run.
  286.  
  287.   Review:
  288.    In this part:
  289.       We introduced the B and D commands.
  290.  
  291.    These commands:
  292.       The B command is similar to the <Alt-B> command we can type on the
  293.       keyboard.  It ensures the TNC is in Command Mode.
  294.  
  295.       The D command causes a delay in the Script processing for a
  296.       specified number of seconds.
  297.  
  298.  
  299.    The syntax required:
  300.       for the B command:
  301.          B      (just a single character -
  302.                  there are no other parameters required)
  303.  
  304.       for the D command:
  305.          D seconds
  306.        eg:
  307.          D 3
  308.          D 60
  309.  
  310.       There is another form of the D command we have not used here.  This
  311.       form allows you to delay UNTIL a certain time of day.  To do that
  312.       you type the D command as follows:
  313.          D hh:mm
  314.       for example:
  315.          D 21:45
  316.       which tells paKet to delay until 9:45pm before continuing.
  317.  
  318.  
  319.    Practical exercise
  320.       Modify FIRST.SCP to include these additional Script commands and run
  321.       it again by typing <Alt-S>.
  322.  
  323.       Notice the delays and the effect they have on the screen display?
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.                                Page 246
  336.  
  337. Script Tutorial - the W and Q commands
  338.  
  339.    The D command is a fixed delay - it will always wait for that same
  340.    period of time.  So if we used that method of separating our commands,
  341.    we would find the Script taking more time than is really necessary,
  342.    because most commands would not take the full 3 seconds to process.
  343.  
  344.    You could try a shorter delay to speed things up but sometimes we might
  345.    need an even longer delay, for example if waiting for a response from
  346.    another station.  A fixed delay just does not suit.
  347.  
  348.    There is a better way!   The "W" command will Wait for a period of
  349.    time, looking for a particular string of characters.  So if we include
  350.    the following line after sending a command:
  351.  
  352.          W 10,cmd:
  353.  
  354.    the Script will wait for up to 10 seconds, and while waiting it will
  355.    be looking for the string "cmd:".  If the 10 second period expires
  356.    before that string is received, paKet will continue processing from the
  357.    next line in the Script.
  358.  
  359.    On the other hand, if that string ("cmd:" in this example) is detected,
  360.    paKet will immediately cancel the wait, skip the next line in the
  361.    Script and continue processing from the following line.
  362.  
  363.    Note the string you specify in the Wait command does not have to be a
  364.    full line as received from the TNC.  paKet can match any part of the
  365.    incoming data. So you could have:
  366.       W 20,VK2DHU
  367.    and the Wait would be satisfied if paKet receives:
  368.       *** CONNECTED to VK2DHU
  369.  
  370.    When you write a Wait command, be sure to specify a time delay that is
  371.    much longer than the time you would reasonably expect for the string to
  372.    appear.  Processing will continue immediately the string is detected so
  373.    in normal circumstances you will not have to wait for the entire period.
  374.  
  375.    In the example we are using here, we are waiting for the "cmd:" prompt
  376.    to come up after we send a command to the TNC.  So a 10 second delay is
  377.    more than enough, in fact we could make that 5 seconds and still be
  378.    quite comfortable.  So, if the Script times out after that period,
  379.    there must be something wrong.  When that situation arises, I generally
  380.    want to abandon the Script and go look to see what caused the problem.
  381.  
  382.    The "Q" command tells paKet to Quit the Script.  This command has no
  383.    parameters.
  384.  
  385.    So, let's modify our FIRST.SCP again to replace the 3 second Delay with
  386.    a Wait and a Quit command, so it looks as follows:
  387.  
  388.  
  389.  
  390.  
  391.                                Page 247
  392.  
  393.          B
  394.          W 5,cmd:
  395.          Q
  396.          S MCON OFF
  397.          W 5,cmd:
  398.          Q
  399.          S CONOK ON
  400.  
  401.    When we run this one, paKet will issue the Break command and wait for
  402.    the TNC to respond with its "cmd:" prompt.  If that does not appear
  403.    within 5 seconds, processing will drop down to the next line where the
  404.    Q command will abort the Script.   If your TNC is one that does not
  405.    produce a "cmd:" after the Break, you will wait for the full 5 seconds
  406.    before the Script aborts!  In your case, remove the W and Q commands
  407.    after the Break and go straight on to the first Send command.
  408.    But in normal circumstances, the TNC will respond with its "cmd:"
  409.    prompt and, with the Wait satisfied, the Script will immediately skip
  410.    the Q command on the next line and continue processing our S command.
  411.    Then it will wait again for another "cmd:", and so on...
  412.  
  413.    If you wanted to, you could add another Wait (and Quit) command after
  414.    the last Send but that is not really necessary here in this example.
  415.  
  416.  
  417.   Review:
  418.    In this part:
  419.       We introduced the W and Q commands.
  420.  
  421.    These commands:
  422.       The W command is a selective Wait. There are two parameters here,
  423.       separated by a comma.  We must specify a maximum time to wait (in
  424.       seconds) as well as specifying the string to wait for.
  425.  
  426.       The Q command is a single letter command to Quit the Script.
  427.  
  428.    The syntax required:
  429.       for the W command:
  430.          W seconds,text
  431.        eg:
  432.          W 30,CONNECTED to
  433.          W 120,messages waiting
  434.  
  435.       for the Q command:
  436.          Q      (just a single character -
  437.                  there are no other parameters required)
  438.  
  439.    Practical exercise
  440.       Change FIRST.SCP again and replace the D command with the W and Q
  441.       commands as shown.
  442.  
  443.       Run it again and watch how this Script is performed more quickly
  444.       than the previous one.  You can see why the Wait command is to be
  445.       preferred over the standard Delay command for this type of
  446.       application.
  447.                                Page 248
  448.  
  449. Script Tutorial - the G and : commands
  450.  
  451.    In modern Programming Schools, the humble GOTO statement is frowned
  452.    upon.  But it is alive and well in paKet Scripts.  (As it is in DOS's
  453.    BATCH facility)
  454.  
  455.    Usually paKet will move through the Script from beginning to end.  It
  456.    starts with the first line, then moves to the second line, then the
  457.    third etc until it reaches the last line of the Script.  A "G" (Goto)
  458.    command allows us to vary that sequence, telling paKet we now want it
  459.    to proceed from somewhere other than the next line in the Script.
  460.  
  461.    To use a Goto command we need to have a "Label" somewhere in the Script
  462.    and in the Goto command we specify the name of that label. The Label is
  463.    any line beginning with a colon (":").  Consider the following example:
  464.  
  465.          B
  466.          :start
  467.          S CONVERSE
  468.          S This is my regular 15 minute Beacon message.
  469.          B
  470.          D 900
  471.          G START
  472.  
  473.    In this example we have:
  474.       - A Break command so we know we are starting in Command Mode.
  475.  
  476.       - The second line is a label because it begins with a colon.
  477.         This line has no effect on the processing, it is just used as a
  478.         marker for the G command we will come to shortly.
  479.  
  480.       - It sends a CONVERSE command to the TNC (we were in Command Mode
  481.         don't forget) followed by a one-line message, before returning to
  482.         Command Mode again with another Break code.
  483.  
  484.       - The Script will delay for 900 seconds (that is 15 minutes).
  485.  
  486.       - Then we come to a Goto command which tells the Script to adjust
  487.         itself so its current line is the line where we wrote the ":start"
  488.         label.  That means it will send another CONVERSE command etc etc
  489.         and do it all again.
  490.  
  491.    This Script will go forever - there is no way out.  It is what
  492.    programmers call a "loop".  Of course you can press <Esc> at any time
  493.    to cancel a Script so you are still in control here.
  494.  
  495.    Note I used lower case when writing ":start" and upper case when writing
  496.    "G START".  I did that deliberately to demonstrate paKet is not fussy
  497.    about the case for the label.  If you spell it the same it will be OK.
  498.  
  499.    A label would usually be one word because that is how most programming
  500.    languages use labels.  But here a label can be an entire line if you
  501.    want.  You just have to ensure the Goto command specifies that full
  502.    string if you want it to match.
  503.                                Page 249
  504.  
  505.  
  506.   Review:
  507.    In this part:
  508.       We introduced the G command and Labels (":").
  509.  
  510.    This commands:
  511.       The G command is a Goto.  The Goto command must specify the label
  512.       which identifies the point in the Script where processing is to
  513.       continue.
  514.  
  515.       A Label is any line beginning with a colon (":").
  516.       The label is simply used as a marker which may be specified in a
  517.       Goto command.   paKet does no processing with a Label.
  518.  
  519.    The syntax required:
  520.       for the G command:
  521.          G text       (where "text" is a Label in this Script File)
  522.        eg:
  523.          G START
  524.          G We are now connected
  525.  
  526.       for the Label:
  527.          : text
  528.        eg:
  529.         : START
  530.         : We are now connected    --- Note the leading blank is ignored so
  531.         :WE ARE NOW CONNECTED     --- these labels are considered "equal"
  532.  
  533.  
  534.    Practical exercise
  535.       Create the Script as shown in this section, call it SECOND.SCP and
  536.       store it in your Scripts directory.
  537.  
  538.       Feel free to change the "Beacon" text to anything that suits you and
  539.       for testing you could reduce the 900 secs to 5 secs, just to make it
  540.       quicker to test your Script when you run it.
  541.  
  542.       Watch your TNC switch from Command Mode to Converse Mode and back
  543.       again after it sends the Beacon Text, and note the indicator
  544.       "SCRIPT" is showing in the Status Window while the Script is running.
  545.  
  546.       Press <Esc> to cancel the Script when you want to stop it.
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.                                Page 250
  560.  
  561. Script Tutorial - the  * and E commands - documenting your Script
  562.  
  563.    You could used a Label as a comment in your Scripts.  As I mentioned
  564.    above, a label has no effect on the processing so we can add several of
  565.    these "labels" to our Scripts as a form of documentation. For example
  566.    we could modify the example Script, SECOND.SCP, we were using here to
  567.    look something like:
  568.  
  569.          : Let's start with a BREAK code to ensure we are in Command Mode
  570.          B
  571.          :--------------------------------------------------------------
  572.          : The following line is the START label - the start of our loop
  573.          :--------------------------------------------------------------
  574.          :start
  575.          :--------------------------------------------------------------
  576.          : Set CONVERSE Command, send a message, return to Command Mode
  577.          S CONVERSE
  578.          S This is my regular 15 minute Beacon message.
  579.          B
  580.          :--------------------------------------------------------------
  581.          : Delay for 900 seconds which is 15 minutes
  582.          D 900
  583.          :--------------------------------------------------------------
  584.          : Now go back up to the "start" label to send another beacon
  585.          G START
  586.  
  587.    Yes OK, I might have gone a bit overboard here with the comments, but if
  588.    I had not explained the various commands or the concept of a loop, this
  589.    Script might have seemed confusing to some people.  In Scripts and in
  590.    conventional programming, I like to see plenty of comments.  If it is
  591.    too difficult to easily explain in a comment, there is something wrong
  592.    with your logic!  The addition of comments can make a Script more easily
  593.    understood, especially if you send a copy of your Script to someone else.
  594.  
  595.    A paKet Script file is limited to 200 lines.  I decided to impose some
  596.    limit to make it easier for paKet to manage the processing.  We can get
  597.    around that limit by using the Call command which we will see a little
  598.    later.  But I mention it here because each Script command line,
  599.    including a Label, is counted as one line.   If you do happen to be
  600.    writing a large Script and are approaching the 200 line limit, you
  601.    should be aware of this and reduce the number of unnecessary "labels".
  602.  
  603.   * - a real comment.
  604.    May I introduce the "*" command?   We didn't have this in earlier
  605.    versions of paKet, but this one is a genuine comment - it's not really
  606.    a command at all.  Although a Label does not actually DO anything, it
  607.    still must be included in case we need it for a Goto command.
  608.  
  609.    But a comment line, that is any line beginning with an asterisk ("*"),
  610.    is not counted as part of the Script when it is loaded into memory.  So
  611.    you can have as many of these comment lines as you like without
  612.    carrying any overhead in the Script.  Obviously this is to be preferred
  613.    to using Labels for documenting your Scripts.
  614.  
  615.                                Page 251
  616.  
  617.    So, in the previous example it would be better if you replaced the
  618.    colon (":") with an asterisk ("*") in every one of the Label/comments -
  619.    except of course the REAL label, the ":start" label!
  620.  
  621.   E command
  622.    Labels and comments are visible in the Script file when you edit or
  623.    type the file, but while the Script is running they are not seen.
  624.  
  625.    The E command is documentation with a difference!   The E command will
  626.    Echo to the screen all the text on this line, so you can use this as a
  627.    form of documentation which is always seen by the paKet operator.  The
  628.    information appears on the screen in the Communications Window as if it
  629.    was received from the other station. It will also appear in your log
  630.    file if it happens to be open at the time.
  631.  
  632.    This command could be used to:
  633.       - inform the paKet operator of progress through various stages of
  634.         processing as the Script is performed (especially if it is a
  635.         complex Script taking some time to complete), or
  636.       - it could be used to display some operator instructions at the
  637.         beginning of the Script, or
  638.       - it could be used simply to Jazz Up your Script to make it look
  639.         more impressive.
  640.  
  641.    Let's have another look at our SECOND.SCP, this time with some
  642.    different "documentation"...
  643.          *********************************************************
  644.          *                      SECOND.SCP                       *
  645.          *                                                       *
  646.          *  This Script will transmit a "Beacon" message every   *
  647.          *  fifteen minutes.  The text of the Beacon is as shown *
  648.          *  here in this Script.                                 *
  649.          *                                                       *
  650.          *  The 15 minute period may be changed by altering the  *
  651.          *  D command to a different value.                      *
  652.          *********************************************************
  653.          *
  654.          E Running Script file:  SECOND
  655.          B
  656.          :start
  657.          *****************************************
  658.          *   This part is done every 15 minutes  *
  659.          *****************************************
  660.          S CONVERSE
  661.          S This is my regular 15 minute Beacon message.
  662.          E
  663.          E      +----------------------------------------------------+
  664.          E      | Press <Esc> if you want to abort the Beacon Script |
  665.          E      +----------------------------------------------------+
  666.          E
  667.          B
  668.          *         Note - 900 seconds is the same as 15 minutes
  669.          D 900
  670.          G START
  671.                                Page 252
  672.  
  673.    Here we see the comments using the asterisk now.  This is better than
  674.    using Labels for comments because when the Script is loaded into memory
  675.    for processing, these comment lines are ignored - they are not even
  676.    loaded into memory with the rest of the Script.  Yet they remain in the
  677.    Script file on disk so we have the benefit of that documentation
  678.    without any overheads or limitations.
  679.  
  680.    The Echo lines will be displayed on the paKet screen as the Script is
  681.    running.  I have added a couple of blank lines and a "box" around the
  682.    message that is Echoed each time around the loop - just trying to be a
  683.    bit fancy!
  684.  
  685.    I think this is sufficient to demonstrate the concepts of commenting
  686.    your Scripts, both with the genuine comments and with Echo commands.
  687.    It DOES make a difference, I think.
  688.  
  689.   Review:
  690.    In this part:
  691.       We introduced the E command and Comments ("*").
  692.  
  693.    These commands:
  694.       The E command is a command to Echo text on the display while the
  695.       Script is running.  The rest of the line is displayed as if it was
  696.       received from the other station.
  697.  
  698.       A Comment is any line beginning with an asterisk ("*").
  699.       Comment lines are not loaded into memory when running a Script so
  700.       you can add as many Comments as you like to the Script File on disk
  701.       without affecting the performance of the Script.
  702.  
  703.    The syntax required:
  704.       for the E command:
  705.          E text
  706.        eg:
  707.          E We are starting the SECOND Script File ...
  708.          E The TNC should be back in Command Mode by now.
  709.  
  710.  
  711.       for the Comments:
  712.          * (text)       (The asterisk is required but text is optional)
  713.        eg:
  714.          * This Script was created by Tony Lonsdale on March 8th
  715.          * The time delay could be increased if the frequency is busy.
  716.  
  717.    Practical exercise
  718.       Edit our first Script file, FIRST.SCP, and add some comments plus an
  719.       Echo command or two.
  720.  
  721.       Add a MYCALL command to send your callsign to the TNC.
  722.  
  723.       Run that Script again and observe the effect of the Echo commands.
  724.  
  725.  
  726.  
  727.                                Page 253
  728.  
  729. Script Tutorial - the C and R commands
  730.  
  731.    I mentioned earlier that a Script file is limited to 200 lines, not
  732.    counting Comment lines.
  733.  
  734.    If you have a need for more than 200 lines, or if you have a more
  735.    complex "application" you could structure your Script processing into
  736.    modules, each of which may be up to 200 lines long.
  737.  
  738.    Then you can use the "C" command to call another Script.  Suppose we
  739.    had three Script files, PART1.SCP, PART2.SCP and PART3.SCP and we
  740.    wanted to run them all in sequence as one single task.  We could create
  741.    another Script, let's call it MAIN.SCP as follows:
  742.  
  743.          E Beginning the 3 part series...
  744.          C PART1
  745.          E Part 1 completed
  746.          C PART2
  747.          E Part 2 completed
  748.          C PART3
  749.          E Part 3 completed
  750.  
  751.    In this example, we run the MAIN Script.  I have added a few Echo
  752.    commands, to demonstrate its use in a more complex Script.  When MAIN
  753.    is running the first thing it does (after the Echo) is to Call
  754.    PART1.SCP.  paKet will load and run the PART1 Script file, then it will
  755.    return to MAIN where it left off... this time dropping down to the next
  756.    Echo then to another Call command which is the Call to PART2.  That one
  757.    is loaded and run, and then back in MAIN, paKet will do PART3 before
  758.    the MAIN Script is completed and control is returned to paKet's normal
  759.    communications mode.
  760.  
  761.    So you can see we can overcome the 200 line limit by dividing our
  762.    really long Scripts into two or more smaller ones and use the Call
  763.    command to perform them all.
  764.  
  765.    There is no practical limit to the number of nested Scripts (depends on
  766.    the amount of memory you have available).  So in our example, the PART1
  767.    Script file could Call another Script, say PART1A. And that PART1A
  768.    Script could call yet another one called ummm, PART1B. In every case,
  769.    when a Script is completed it "Returns" to the one that called it, and
  770.    if we are back to the highest level (or if we had only one level to
  771.    start with), control returns to paKet.
  772.  
  773.  
  774.   Return
  775.    We have seen that when a Script is completed, that is when the last
  776.    line has been processed and there is no more to do, that Script is
  777.    terminated.   Control is returned to the calling Script if any, or to
  778.    paKet.
  779.  
  780.    There may be times where we would like to "Return" before we reach the
  781.    end of a Script.  The "R" command will do this for us.  Let me
  782.    demonstrate with an example:
  783.                                Page 254
  784.  
  785.          E
  786.          E  **********************************************************
  787.          E  *                This is the BBS Script                  *
  788.          E  *      This Script establishes contact with the BBS.     *
  789.          E  *                                                        *
  790.          E  *         Once it has established that contact,          *
  791.          E  *      it returns to paKet or to the calling Script.     *
  792.          E  *                                                        *
  793.          E  **********************************************************
  794.  
  795.          * Send a BREAK to the TNC to get into Command Mode
  796.          B
  797.  
  798.          * Now, SEND a CONNECT command
  799.          *  NOTE  change this Send command to use your own BBS's callsign
  800.          S C VK2ATM-1
  801.  
  802.          * ... and wait up to 20 seconds for the TNC's CONNECTED message
  803.          W 20,CONNECTED to
  804.          G noanswer
  805.  
  806.          * We are now connected, so we can leave this Script now!
  807.          R
  808.  
  809.          :noanswer
  810.          E *** The BBS did not respond within 20 seconds ***
  811.          Q
  812.  
  813.    I have inserted some blank lines in this example.  These, like the
  814.    comment lines will be ignored when the Script is loaded into memory so
  815.    if you think it makes your Script File easier to read with some
  816.    additional spacing, feel free to add them to your Scripts.  It will not
  817.    cost you anything, except in very rare circumstances it might take a
  818.    little more disk space.
  819.  
  820.    This Script is using commands we have already covered.  So, if you are
  821.    still reading this part of the Manual, you should be able to figure out
  822.    what the Script is doing by now.  If you are not still reading, then
  823.    ... uh no, we won't go into that!
  824.  
  825.  
  826.    This Script might be called from another Script or we can call it up
  827.    from the keyboard with the <Alt-S> command.
  828.  
  829.    In the example shown above I have a simple connection to my BBS so the
  830.    20 seconds I allowed should be quite adequate there.  If your system
  831.    requires a more complex connect path, you might need to make that
  832.    somewhat longer.
  833.  
  834.    In this example, if we receive the usual acknowledgement within the 20
  835.    second period, the Script will come down to the "R" command and
  836.    terminate.   The job is done!
  837.  
  838.    So the R command allows us to return from any point in our Script.
  839.                                Page 255
  840.  
  841.  
  842.    Note the difference between a Return command and a Quit command which
  843.    we use if the BBS does not respond.   A Quit is usually used when
  844.    something is wrong and we just want to get out of here.  It will cause
  845.    an error message to be displayed and the entire Script process will be
  846.    aborted.  So if you are running in a nested Script, a Quit command will
  847.    not only cancel that Script but any others that might have called it.
  848.    You are back in paKet.   Unless there is a problem, a Return command is
  849.    a tidier way out and is the preferred way of leaving a Script.
  850.  
  851.  
  852.  
  853.   Return Code
  854.    The Return command can have an optional Return Code.  This could be
  855.    used to indicate to the calling Script the results of a particular
  856.    operation.  Let's have another look at the above example. Instead of
  857.    the Quit at the end, we could issue a Return command with a return
  858.    code.  For example:
  859.  
  860.          .
  861.          .
  862.          .
  863.          :noanswer
  864.          E *** The BBS did not respond within 20 seconds ***
  865.          R 1
  866.  
  867.    The "R 1" will return to the calling Script just like any other Return
  868.    command, but this one will also take with it a return code of 1.  If no
  869.    return code is specified, paKet assumes a return code of 0.
  870.  
  871.    Then a calling Script could look at this return code and determine
  872.    whether we are connected to the BBS or not.  If the code is 0 it knows
  873.    everything is OK but if it is 1 it might decide to Quit or take some
  874.    other action?
  875.  
  876.    At this stage, just keep in mind that you can add a return code to the
  877.    Return command.  When we discuss Variables later, we will see how it is
  878.    used in the calling Script.
  879.  
  880.  
  881.   Review:
  882.    In this part:
  883.       We introduced the C and R commands.
  884.  
  885.  
  886.    These commands:
  887.       The C command will Call another paKet Script file.
  888.  
  889.       The name of the other Script is given on the Call command line.  If
  890.       that Script is not in the normal Scripts directory, the Call command
  891.       can specify full path details so the program can find that Script
  892.       file.
  893.  
  894.  
  895.                                Page 256
  896.  
  897.       The R command is Return command.
  898.  
  899.       When this command is performed in a Script, that Script is
  900.       terminated and control is returned to the calling Script or to
  901.       paKet, as appropriate.
  902.  
  903.    The syntax required:
  904.       for the C command:
  905.          C Script-file-name
  906.        eg:
  907.          C PART1
  908.          C C:\TEMP\ONCEONLY.SSS
  909.  
  910.       for the R command:
  911.          R return code     (The return code is optional)
  912.        eg:
  913.          R
  914.          R 55
  915.  
  916.  
  917.    Practical exercise
  918.       Create a new Script, BBS.SCP, from the example given above.  Use
  919.       the first example (with the Quit command) because we have not yet
  920.       fully covered the handling of Return Codes.
  921.  
  922.       Test it by pressing <Alt-S> and establish contact with your BBS.
  923.       Don't forget to change the callsign, and add any other path details
  924.       required for your own BBS.  You might need more than 20 seconds too.
  925.  
  926.       This BBS Script will be used in the exercise for the following
  927.       section.
  928.  
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.                                Page 257
  952.  
  953. Script Tutorial - the AD, AU and AC commands
  954.  
  955.  File Transfers
  956.    Here for the first time we see some two letter commands.  These are
  957.    ASCII file transfer commands.  An ASCII file, by the way, is a file
  958.    containing plain, printable text.
  959.  
  960.    "AD" is an ASCII Download command, and we must specify on the command
  961.    line the name of the file we want to create.
  962.  
  963.    When this command is performed by the Script processing, paKet will open
  964.    the file we nominate.  It works in a similar manner to the <F6> key so
  965.    now everything received in this Stream will be written to that file.
  966.  
  967.    That file will be closed if we receive a <Ctrl-Z> code from the other
  968.    station, but we can also close it with an "AC" Script command.
  969.  
  970.    If the named file is already present on our disk, paKet will not change
  971.    that existing file but will create a new file with a different
  972.    extension, starting with .000 but incrementing that number until it
  973.    finds a filename that does not already exist!
  974.  
  975.    Once the file is opened and ready to receive data, processing continues
  976.    from the next line in our Script.
  977.  
  978.    The "AU" command is an ASCII Upload command, and once again we must
  979.    specify on the command line the name of the file we want to send.
  980.  
  981.    When this Script command is processed, paKet will open that file and
  982.    send the entire contents of that file to the TNC.  When the last byte
  983.    has been sent, the file is closed and paKet continues Script processing
  984.    from the next line.
  985.  
  986.    What's this?  You want more examples?
  987.  
  988.    Hang on, I just want to mention the other type of file transfer -
  989.    Binary File transfers.
  990.  
  991.  
  992.   YD and YU commands
  993.   ------------------
  994.    These commands are the Binary File Transfer commands.  The name is
  995.    taken from the original Packet Radio file transfer protocol, YAPP.  So
  996.    these commands refer to "YAPP Download" and "YAPP Upload".  Of course
  997.    paKet can use the advanced pP Protocol too and it will automatically
  998.    select the advanced protocol if necessary. You don't have to worry
  999.    about that - let paKet take care of it.
  1000.  
  1001.    A Binary File can be any type of file at all.  You can use these
  1002.    commands to send and receive plain ASCII text files if you wish, but
  1003.    they are more commonly used to transfer files which contain non
  1004.    printable codes; files such as programs (.COM and .EXE files) or any
  1005.    archived file (eg: files with .LZH or .ZIP extension).
  1006.  
  1007.                                Page 258
  1008.  
  1009.    The use of these commands is very similar to the ASCII file transfer
  1010.    commands.  The process is also covered fully in the Windows section of
  1011.    this Manual - see the part on the Binary File Transfer Window.  Also
  1012.    have a look at <F7> and <F8> in the Keyboard Commands section of this
  1013.    Manual.
  1014.  
  1015.    If you want to send a Binary File you must specify the file name on the
  1016.    "YU" command line.   When receiving a Binary File, the "YD" command
  1017.    alone is quite sufficient because the other station will include the
  1018.    filename in the Protocol Header.
  1019.  
  1020.    OK, OK... those examples.
  1021.  
  1022.    Here is a Script to call the BBS and List all unread messages,
  1023.    capturing those details into a file on our disk. Conveniently, it will
  1024.    Call the BBS Script we created earlier to establish connection with the
  1025.    BBS so we won't have to go into all that detail here.
  1026.  
  1027.          ************************************************
  1028.          *                 BBSLIST.SCP
  1029.          *
  1030.          *  This Script will connect to the BBS, List
  1031.          *  all unread messages and Bulletins, storing
  1032.          *  all that data in a file named BBSLIST.DAT
  1033.          *  on our hard disk.
  1034.          ************************************************
  1035.          C BBS
  1036.          *
  1037.          * The BBS Script will Quit if the connection is not established
  1038.          * so if it comes back here we must be connected now!
  1039.          *
  1040.  
  1041.          * Open a file to capture the BBS message list
  1042.          AD C:\PAKET\BBSLIST.DAT
  1043.          E The text file is now open and ready to receive data...
  1044.  
  1045.          * Ask the BBS to "List" the last 10 messages in its Mailbox
  1046.          S LL 10
  1047.  
  1048.          *
  1049.          * OK, that's done, now we can close our data file
  1050.          *
  1051.          AC
  1052.          * and disconnect from the BBS
  1053.          B
  1054.          S D
  1055.          R
  1056.  
  1057.    That looks easy enough.  But when we run it, we find there are no
  1058.    message details in our new data file, even though we might have seen
  1059.    them on the screen as they were received from the BBS!   What went
  1060.    wrong?   Can you figure it out?  This is called "debugging" and this
  1061.    aspect of programming can be the most frustrating part of it.
  1062.  
  1063.                                Page 259
  1064.  
  1065.    Yes, "programming".  Whether you knew it or not, you are now a computer
  1066.    programmer.  Writing a program means to develop a series of
  1067.    instructions for the computer to follow.  That is exactly what we are
  1068.    doing here.
  1069.  
  1070.    Anyway, now that we have something in common, let's investigate the
  1071.    problem we have with this program... er, I mean Script.  What is
  1072.    happening here?
  1073.  
  1074.    No, come to think of it, I might leave you to have a go at debugging
  1075.    that one yourself.  I'll come back to it later.  We'll make that part
  1076.    of your Practical exercise for this section.
  1077.  
  1078.   Review:
  1079.    In this part:
  1080.       We introduced the AD, AC and AU commands.
  1081.       We also covered the YD and YU commands.
  1082.  
  1083.    These commands:
  1084.       The AD command ("ASCII Download") will open a text file on disk and
  1085.       will write all incoming data to that file until it is closed.
  1086.  
  1087.       The AC command ("ASCII Close") will close the file we opened with
  1088.       the AD command.
  1089.  
  1090.       The AU command ("ASCII Upload") will send the contents of the
  1091.       specified text file to the TNC.
  1092.  
  1093.       The YD command is the Binary File Transfer Download command, which
  1094.       is used to transfer a Binary File FROM the other station.
  1095.  
  1096.       No parameters are required here because the other station will
  1097.       include those details with the file header, and paKet will know what
  1098.       to do with it.  Before issuing the YD command in your Script you
  1099.       should make sure the other station is ready to transmit in YAPP or
  1100.       pP mode.  This usually involves sending some sort of command to the
  1101.       other station, such as the BBS's "YD" command to tell it we want it
  1102.       to send one of its files to us.
  1103.  
  1104.       The YU command is the Binary File Transfer Upload command, which is
  1105.       used to transfer a Binary File TO the other station.
  1106.  
  1107.       We must tell paKet which file we want to send on the YU command
  1108.       line.  Again we should ensure we have issued the appropriate
  1109.       commands to the other station to prepare it to receive our file
  1110.       before we issue this YU command in our Script.
  1111.  
  1112.     The syntax required:
  1113.       for the AD command:
  1114.          AD New-file-name
  1115.        eg:
  1116.          AD MSGS.DAT
  1117.          AD D:\TEMP
  1118.  
  1119.                                Page 260
  1120.  
  1121.       for the AC command:
  1122.          AC      (there are no parameters required)
  1123.  
  1124.       for the AU command:
  1125.          AU file-name
  1126.        eg:
  1127.          AU CMDS.DAT
  1128.          AU C:\PAKET\PREPARED.MSG
  1129.  
  1130.       for the YD command:
  1131.          YD      (there are no parameters required)
  1132.  
  1133.       for the YU command:
  1134.          YU file-name
  1135.        eg:
  1136.          YU PAKET.EXE
  1137.          YU C:\GOODIES\FRED.LZH
  1138.  
  1139.  
  1140.    Practical exercise
  1141.       Create the BBSLIST.SCP from the example given above. This calls the
  1142.       BBS.SCP we discussed in the previous section so it will be easier to
  1143.       do this exercise if you have done that one and got it working.
  1144.  
  1145.       Load and run this BBSLIST Script, watching the Screen closely as it
  1146.       runs.  If you have successfully Called the BBS Script file, you will
  1147.       see the Connect command appear on your screen.  If it aborts you
  1148.       will get a message pop up - in that case you will have to try to
  1149.       find out why it aborted.  Is everything typed correctly, exactly as
  1150.       shown here?  Have you made any changes - if so they must be checked
  1151.       carefully.  Maybe the problem is simply the BBS did not have time to
  1152.       respond within the time you have allowed? (That's easy to fix!)
  1153.  
  1154.       Assuming you do get a successful connection and the BBS sent back
  1155.       some message details in response to our List command, it should all
  1156.       be in the BBSLIST.DAT data file we specified with our AD command.
  1157.  
  1158.       If it is not there, we have to find out what went wrong.  We have to
  1159.       go back over the Script commands, examining each one carefully and
  1160.       try to "play computer", that is to imagine WE are the computer,
  1161.       religiously and blindly following each and every instruction.
  1162.  
  1163.       It might take a little experience but I am sure you will soon spot
  1164.       the problem here.  We have told the system to send a List command to
  1165.       the BBS.  Fine, it does that.  Then it drops down to the next
  1166.       command which closes the file!  Already!  Hey, the BBS is still
  1167.       looking for those messages and we have closed the file already!  We
  1168.       need some sort of Delay, preferably a Wait in here so we do not
  1169.       close the file until AFTER we get those message details.
  1170.  
  1171.       See if you can work out what to do here, but I'll give you a hint.
  1172.       I would insert a Wait command after sending the LL 10.
  1173.  
  1174.  
  1175.                                Page 261
  1176.  
  1177. Script Tutorial - the ! command
  1178.  
  1179.    Wouldn't it be nice if we could run some DOS commands from within paKet?
  1180.  
  1181.    Oh, I thought you would never ask...
  1182.  
  1183.    The "!" command can be used in a Script to do just that.  With this
  1184.    command paKet will pass over to DOS whatever you place on this Script
  1185.    line.  So if you have:
  1186.  
  1187.          ! COPY C:\PAKET\BIN\UPLOAD\*.LZH A:\
  1188.  
  1189.    paKet will send that COPY command to DOS for processing.  There are no
  1190.    limitations on the type of command you can run here.  If you can run it
  1191.    at the keyboard from the <F9> DOS Gateway, then you can run it here
  1192.    from the Script.  The paKet program is still in memory of course so it
  1193.    is taking up a lot of precious memory.  Hopefully there is enough left
  1194.    to run your DOS command?  It might be an internal DOS command such as
  1195.    this COPY command or DIR, etc.  It could be a program such as:
  1196.  
  1197.          ! C:\DOS\MEM /C > D:MEM.LST
  1198.  
  1199.    although in that case you do not even need to specify the "C:\DOS\"
  1200.    if DOS can find that MEM program in its PATH.
  1201.  
  1202.    Or you can use a DOS batch file.  So if you had a batch file called
  1203.    say, HOUSEKEP.BAT available in the current directory or within the DOS
  1204.    PATH, you could have:
  1205.  
  1206.          ! HOUSEKEP
  1207.  
  1208.    If the Script command line contains just the "!" command without any
  1209.    parameters, paKet will call up DOS and leave you with the DOS prompt -
  1210.    just like pressing <F9>.
  1211.  
  1212.    I decided to avoid any pause after this DOS command is performed.  I
  1213.    could have added some sort of pause where you have to press a key or
  1214.    something like that to give you time to peruse the results of this DOS
  1215.    operation.  However, that tends to defeat the purpose of automating the
  1216.    process in a Script!  So when the DOS command is processed and control
  1217.    returns to paKet's Script, everything proceeds without any delay.  This
  1218.    means you will not have time to look at the DOS screen to see what
  1219.    happened.  If you want to see that screen I suggest you make up a DOS
  1220.    Batch file with a PAUSE command and specify that Batch file here as
  1221.    your Script command.
  1222.  
  1223.    You should keep in mind that a REMOTE user will have access to any
  1224.    Script file in your Scripts directory, if it has the standard .SCP
  1225.    extension.  So if you have a Script to do some significant DOS
  1226.    processing, such as erasing files from your disk, or even to ...
  1227.    (shudder) ... to format your disk, you might need to keep that Script
  1228.    out of the Scripts directory or perhaps to rename its extension to
  1229.    something other than SCP.  That way, you will not risk having some
  1230.    (perhaps innocent) REMOTE user Perform that Script without your approval.
  1231.                                Page 262
  1232.  
  1233.  
  1234.   Review:
  1235.    In this part:
  1236.       We introduced the ! command.
  1237.  
  1238.    This command:
  1239.       The ! command is a Script command to execute a DOS program,
  1240.       including a BATch file or an internal DOS command.
  1241.  
  1242.    The syntax required:
  1243.       ! (DOS-program-name/command)    (The parameter is optional)
  1244.     eg:
  1245.       ! LHA M C:\PAKET\SAVELOG C:\PAKET\*.LOG
  1246.       ! SCANDISK
  1247.       !
  1248.  
  1249.    Practical Exercise:
  1250.       I am sure it won't take too much imagination on your part to come
  1251.       up with all sorts of things you could do with this command.  But
  1252.       just for the simple exercise, make up a Script with just one DOS
  1253.       command: display the contents of your CONFIG.SYS file on the screen.
  1254.       If you use the DOS "TYPE" command it will appear briefly then
  1255.       quickly disappear as control returns to paKet.  If you have the LIST
  1256.       program handy, use that.
  1257.  
  1258.       Yes, I know this is a trivial example, but it is pretty harmless
  1259.       too!   Here, let me illustrate:
  1260.  
  1261.          ! LIST C:\CONFIG.SYS
  1262.  
  1263.                 or
  1264.  
  1265.          ! TYPE C:\CONFIG.SYS
  1266.  
  1267.  
  1268.  
  1269.  
  1270.     ------------------------------------------------------------------
  1271.     At this stage I consider we have covered enough about Scripts for you
  1272.     to be able to make effective use of the Script system in paKet.
  1273.  
  1274.     With the commands we have covered I think you could achieve quite a
  1275.     lot of automation in your daily operations.
  1276.  
  1277.  
  1278.     The rest of this section of the Manual contains more information on
  1279.     Scripts and introduces some more sophisticated commands and techniques.
  1280.  
  1281.     By all means read on, and explore the power and creativity that lies
  1282.     in the use of these more powerful commands.  But if you are having
  1283.     trouble keeping up, you might like to get some practice with the
  1284.     commands we have covered so far, and get into the heavy stuff later.
  1285.     ------------------------------------------------------------------
  1286.  
  1287.                                Page 263
  1288.  
  1289. Script Tutorial - the T command
  1290.  
  1291.    A Wait command will wait for a time, looking for a particular string of
  1292.    characters.  This is most useful if that is the only string we are
  1293.    interested in at the time.  A good example of this is the TNC's "cmd:"
  1294.    prompt.  If we issue a command and want to know when the TNC is ready
  1295.    to take another one, the "cmd:" is the only string we need to look
  1296.    for.  Anything else is not really relevant to our needs at the moment,
  1297.    so we can wait for that string and ignore everything else.
  1298.  
  1299.    But things are not always so precise and convenient.  Sometimes there
  1300.    may be several possibilities and we cannot be sure which string will
  1301.    come first, or even IF a particular string will come in at all!
  1302.  
  1303.    This is where the Trap command ("T") can be useful.
  1304.  
  1305.    Trap is a Script facility where we can specify up to 30 different
  1306.    strings to watch out for, each of which has a Label to identify the
  1307.    Script code we want to perform if THAT particular string is detected.
  1308.  
  1309.    Perhaps the best way to illustrate the concept of Traps is to give you
  1310.    a working example. For your Practical Exercise for this section, make
  1311.    up a Script as follows:
  1312.  
  1313.          T The BBS,VK2ATM
  1314.          T pgm,paKet
  1315.          T My friend,Andy
  1316.  
  1317.          E We are starting the Trap Script to look for
  1318.          E some things while we monitor the frequency.
  1319.  
  1320.          :top
  1321.          D 60
  1322.          E We are still in the Trap Script
  1323.          G top
  1324.  
  1325.          * The following Script commands are used only if a Trap occurs
  1326.          :The BBS
  1327.          E We have spotted some BBS activity
  1328.          G top
  1329.          :pgm
  1330.          E Somebody is using paKet around here
  1331.          G top
  1332.          :My friend
  1333.          E Oh, there's my mate Andy!
  1334.          G top
  1335.  
  1336.    This Script starts with three Trap commands.  I suggest you change the
  1337.    text following the comma on these commands to something you are likely
  1338.    to see when monitoring the frequency on your system.
  1339.  
  1340.    In the example shown above the first Trap is looking for the callsign
  1341.    of my local BBS (VK2ATM in my example).  If that string is detected,
  1342.    paKet will perform a Goto to the ":The BBS" Label.
  1343.                                Page 264
  1344.  
  1345.  
  1346.    The second Trap command is looking for the word "paKet"; the third
  1347.    command is looking for the string "Andy".
  1348.  
  1349.    So when I run that Script here, paKet makes a note of these three
  1350.    Traps, then after a couple of Echoes it begins a 60 second delay.
  1351.    During this time anything that is received over the air will be
  1352.    processed and displayed on the screen.  When the 60 second period
  1353.    expires, we get the message "We are still in the Trap Script" then we
  1354.    go back for another 60 second delay.  We get that message every 60
  1355.    seconds just to remind us what we are doing!
  1356.  
  1357.    If, while we are monitoring and displaying incoming data, we receive
  1358.    one of the Trap strings (eg: "paKet") the Script will jump down to the
  1359.    Label specified for that string.  In this example we would go to the
  1360.    :pgm Label and continue processing the Script from there.
  1361.  
  1362.    You can see that will Echo a message about paKet the go back for
  1363.    another turn around the Delay loop.   You can do whatever processing
  1364.    you like there - I am just Echoing a message to keep it simple. The
  1365.    important thing here is to see how the Traps operate.
  1366.  
  1367.    And if the word "Andy" appears anywhere in the monitored data, it will
  1368.    echo a message about my mate Andy before going back around the delay
  1369.    loop.
  1370.  
  1371.    If none of these Trap strings is received, it will just go on repeating
  1372.    the "We are still in the Trap Script" message every 60 seconds.
  1373.  
  1374.    Press <Esc> to cancel this Script.
  1375.  
  1376.  
  1377.    Another (more complicated) example?
  1378.  
  1379.    Suppose our BBS produces the message "You have mail waiting" if there
  1380.    happens to be some new mail in its Mailbox that we have not yet read.
  1381.  
  1382.    We could modify our BBSLIST Script File to include the following Trap
  1383.    command:
  1384.  
  1385.          T mail, You have mail waiting
  1386.  
  1387.    This new command tells paKet to watch out for the "You have mail
  1388.    waiting" string and if it is detected, the Script processing is to
  1389.    continue from the ":mail" Label.
  1390.  
  1391.    Our BBSLIST Script might look something like this:
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.                                Page 265
  1400.  
  1401.          ************************************************
  1402.          *                 BBSLIST.SCP
  1403.          ************************************************
  1404.          T mail, You have mail waiting
  1405.          C BBS
  1406.          AD C:\PAKET\BBSLIST.DAT
  1407.          E The text file is now open and ready to receive BBS data...
  1408.  
  1409.          * We know the TNC has connected, but we should wait for
  1410.          * the normal BBS prompt which includes the "X,Y,Z etc"
  1411.          :wait
  1412.          W 60, X,Y,Z,?) >
  1413.          Q
  1414.  
  1415.          * When the BBS is ready, THEN send our command
  1416.          :list
  1417.          S LL 10
  1418.  
  1419.          * Then wait for the listing to finish before closing our file
  1420.          W 120, X,Y,Z,?) >
  1421.          Q
  1422.          AC
  1423.          B
  1424.          S D
  1425.          R
  1426.  
  1427.          :mail
  1428.          * We come here ONLY IF the Trap detects the Mail Waiting string
  1429.          * Which would be sent while we were waiting for the first BBS prompt
  1430.          W 120, X,Y,Z,?) >
  1431.          Q
  1432.          S RM
  1433.          G wait
  1434.  
  1435.    It is just as well you are now becoming familiar with Scripts because
  1436.    this one is looking a bit complicated now.  But take it steadily, one
  1437.    command at a time and I am sure you will cope with this OK.  It is
  1438.    basically the same as the previous BBSLIST Script with the addition of
  1439.    the Trap command at the top and the ":mail" routine at the bottom.
  1440.  
  1441.    I have removed some of the spacing and comments because it is becoming
  1442.    a bit big to be repeating all that here in this section when you can
  1443.    easily go back a few pages to see the earlier copy.
  1444.  
  1445.    Oh... it looks like I have also added those Waits we were talking about
  1446.    earlier.  Remember that bug we had?   Oh well, you have seen it now so
  1447.    it's too late to cover it up.  We might as well talk about it then...
  1448.  
  1449.    I added a Wait for 60 seconds at first just to wait for the BBS prompt.
  1450.    The other Script we called (BBS.SCP) returns as soon as it sees the
  1451.    TNC's Connected message.  So I added a Wait to give the BBS time to
  1452.    come up with its first prompt before sending the "LL 10".
  1453.  
  1454.  
  1455.                                Page 266
  1456.  
  1457.    Then after sending the "LL 10" another Wait - this time I waited for up
  1458.    to 2 minutes to get the next prompt.  The BBS will send another prompt
  1459.    AFTER it has sent the Listing we requested (I hope 2 minutes is
  1460.    sufficient time).  Then we can close the file.
  1461.  
  1462.    In case you are wondering about that funny string "X,Y,Z,?) >", I
  1463.    should explain that is just the end of the usual BBS prompt string.
  1464.    Yes I know I could have specified the entire prompt string but I
  1465.    figured that much was rather unique and should be more than enough to
  1466.    properly identify the string I was looking for.
  1467.  
  1468.    Anyway, back to the Trap:
  1469.  
  1470.    When our new Script runs, it processes the Trap command first.  That
  1471.    tells paKet to record those details and to maintain a watch for that
  1472.    string.
  1473.  
  1474.    My local BBS might come up with that Mail Waiting message as soon as I
  1475.    connect so it would be received before I get the first Menu Prompt.
  1476.    That means if we are going to get that string at all, it would come in
  1477.    during our 60 second Wait.
  1478.  
  1479.    If we do not happen to have any mail waiting, the BBS will not send
  1480.    that message.  So our Script will perform exactly the same as if we had
  1481.    not bothered about the Trap at all.  It simply sends the "LL 10", waits
  1482.    for another prompt, closes the ASCII file and Disconnects.  So, if the
  1483.    Mail Waiting string does not come in, our new ":mail" routine is not
  1484.    used at all!
  1485.  
  1486.    But, suppose we did have some mail waiting and the BBS did send us that
  1487.    message after we make the connection.... let's follow the logic flow as
  1488.    we run this Script:
  1489.       1. The Trap command is recorded.  That's all that is done at this
  1490.          stage.  paKet simply records both the String we are looking for
  1491.          and the Label we want to associate with that string.  No other
  1492.          action is taken.
  1493.  
  1494.       2. we call BBS.SCP to make the connection.  That will Quit if we
  1495.          fail to make the connection, so if control returns to our BBSLIST
  1496.          Script, we know the TNC is now connected.
  1497.  
  1498.       3. The AD command opens our data file and the Echo command sends a
  1499.          confirmation to the screen.
  1500.  
  1501.       4. We begin a 60 second Wait now, looking for the BBS prompt.  As
  1502.          soon as that is received, we will drop down to the Send command
  1503.          where "LL 10" is sent to the TNC.
  1504.  
  1505.       5. But in this particular case, the BBS sends us the "You have mail
  1506.          waiting" string while we are waiting for its first prompt.
  1507.  
  1508.       6. The Trap processing detects this and switches control over to the
  1509.          ":mail" label.
  1510.  
  1511.                                Page 267
  1512.  
  1513.       7. Here (in the :mail routine) we continue to wait for that first
  1514.          prompt, just to keep things tidy.  When we get the prompt we
  1515.          issue a BBS command to read our mail (that is what the RM is
  1516.          for).
  1517.  
  1518.          Then it can go back up to the ":wait" label because there it will
  1519.          wait for another BBS prompt.  The BBS will send us another
  1520.          prompt when it has finished sending our mail.
  1521.  
  1522.       8. Now that we have our mail, and the BBS has sent its next prompt,
  1523.          telling us it is waiting for another command, we can drop down to
  1524.          the List command and we continue our normal processing from
  1525.          there, eventually closing the data file and disconnecting from
  1526.          the BBS.
  1527.  
  1528.  
  1529.    Yes, it does look rather complicated at first glance, but you can see
  1530.    that if you take each command in turn and follow the logic through,
  1531.    step by step, it does make sense.  And as you gain more experience with
  1532.    Scripts you will be able to read that sort of thing as easily as you
  1533.    read the morning newspaper.   Promise!
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.                                Page 268
  1568.  
  1569. Script Tutorial - the FC, FS and FT commands
  1570.  
  1571.    These commands are the Script Flag commands.  There are three of these
  1572.    commands and each requires a parameter, a number between 0 and 9:
  1573.  
  1574.       FC n     Flag Clear
  1575.       FS n     Flag Set
  1576.       FT n     Flag Test.
  1577.  
  1578.    A "Flag" is simply an indicator we can set (or clear) during the Script
  1579.    to remind us of some condition or circumstance, and that flag can be
  1580.    tested later in that Script.   There are 10 Flags available, 0 to 9.
  1581.  
  1582.    This facility was created in paKet 5 and is included in this version
  1583.    for compatibility with existing Scripts.  Now that we have Variables in
  1584.    paKet 6 (yes, yes I am coming to Variables) you could use them to do
  1585.    the same job.   Anyway, Flags are here so I'll show you how to use
  1586.    them.
  1587.  
  1588.  
  1589.    If we come to some condition we need to know about later we can set a
  1590.    Flag, for example:
  1591.  
  1592.          FS 6
  1593.  
  1594.    This sets Flag number 6.  By the way all Flags are presumed to be Clear
  1595.    (i.e. NOT Set) before a Script starts.
  1596.  
  1597.    You can Clear a Flag with the Flag Clear (FC) command.
  1598.  
  1599.    Then, later in our processing we can test this Flag to see which way we
  1600.    want to go.   The Flag Test (FT) command will look at the Flag we
  1601.    nominate here and if the Flag is set, the next Script line is
  1602.    performed.  But if that Flag is Clear, paKet skips the next line in the
  1603.    Script and continues from the line after that.  Let's have another
  1604.    example:
  1605.  
  1606.          .
  1607.          .
  1608.          FT 6
  1609.          G Gotcha
  1610.          E The Flag was not set
  1611.          .
  1612.          .
  1613.          .
  1614.          : Gotcha
  1615.          E The flag was set...
  1616.          FC 6
  1617.          E ... but is now cleared again
  1618.          .
  1619.          .
  1620.  
  1621.  
  1622.  
  1623.                                Page 269
  1624.  
  1625. Script Tutorial - Variables
  1626.  
  1627.    I'll bet you thought we would never get to Variables!
  1628.  
  1629.    What is a Variable anyway?
  1630.  
  1631.    In its simplest terms, a Variable is a small piece of the computer's
  1632.    memory that we can use in our Script, to store some temporary
  1633.    information.  It may contain varying values because we choose what goes
  1634.    into it!
  1635.  
  1636.    Each of these Variables is identified by a unique name.  There are 36
  1637.    Variables altogether, 26 ordinary Variables and 10 special Variables
  1638.    which I will call "Passed-Parameters".
  1639.  
  1640.    The 26 ordinary Variables are identified by the letters of the alphabet
  1641.    and the syntax we must use is to specify a Variable with a Percent sign
  1642.    followed by a single letter, eg:
  1643.          %A  (or %a  - same Variable)
  1644.          %J
  1645.          %Z
  1646.  
  1647.    The Passed-Parameters are similar but they use numbers from 0 to 9, eg:
  1648.          %0
  1649.          %5
  1650.          %9
  1651.  
  1652.    How are variables used?  Perhaps the easiest way to demonstrate is to
  1653.    introduce a new command:
  1654.  
  1655. Script Tutorial - the M command
  1656.  
  1657.    The Move command moves some data into a Variable.  The syntax required
  1658.    is:
  1659.          M variable,data
  1660.  
  1661.    For example:
  1662.          M %A,VK2DHU
  1663.          M %b,Tony
  1664.          M %K,99
  1665.  
  1666.    All Variables contain text data so that one with 99 actually contains
  1667.    two ASCII characters, not a single numeric value of 99!
  1668.  
  1669.  
  1670.  
  1671.    You may use Variables in any of the Script text strings.  So we could
  1672.    have, for example:
  1673.  
  1674.          T exit,%B is not home
  1675.          E Connecting to %A...
  1676.          S CONNECT %A
  1677.          W 10, Connected to %A
  1678.  
  1679.                                Page 270
  1680.  
  1681.    These commands would be interpreted as follows (assuming the above Move
  1682.    commands have been performed earlier in this Script):
  1683.  
  1684.          T exit,Tony is not home
  1685.          E Connecting to VK2DHU...
  1686.          S CONNECT VK2DHU
  1687.          W 10, Connected to VK2DHU
  1688.  
  1689.    You can choose any of the 26 Variables for any use you wish.  There is
  1690.    just one thing I need to mention.  The %Z variable is used by the
  1691.    Script system to carry the Return Code from a "Called" Script.
  1692.  
  1693.    The Return Code.   Don't tell you've forgotten that already?
  1694.  
  1695.    Alright, let's have another quick look at the Return command. We might
  1696.    usually specify just the single letter "R" to return from a Called
  1697.    Script, but if we wanted to return the result of some operation, we
  1698.    could give it a Return Code by writing something like "R 50".
  1699.  
  1700.    If we did that, the %Z variable would now contain a value of 50.
  1701.  
  1702.    Let's have a look at that again with an example:
  1703.          E Testing the Return Code
  1704.          C SUBS
  1705.          E *** The return code from Subs is %Z ***
  1706.  
  1707.    So if the SUBS Script finished with:
  1708.          R 9
  1709.    then the last line of our Example would Echo on our screen:
  1710.          *** The return code from Subs is 9 ***
  1711.  
  1712.    You can use the %Z Variable for any purpose at all, but remember it
  1713.    might be overwritten by the system if you Call another Script!
  1714.  
  1715.  
  1716. Script Tutorial - Passed-Parameters
  1717.  
  1718.    These are the ten numeric Variables, %0 to %9.
  1719.  
  1720.    When we Call another Script, we have an option to include on the
  1721.    Call command line some additional information, which will be passed to
  1722.    the Called Script. If we have the following line in our MAIN Script:
  1723.          C SUBS,Tony
  1724.  
  1725.    Then the SUBS Script knows what parameter was specified because it is
  1726.    stored in %1 (it is the first parameter on the line).
  1727.  
  1728.    If the SUBS Script included something like:
  1729.          E SUBS Script parameter number 1 contains %1
  1730.  
  1731.    you get no prizes for guessing that will Echo on our screen:
  1732.          SUBS Script parameter number 1 contains Tony
  1733.  
  1734.  
  1735.                                Page 271
  1736.  
  1737.    Each of the parameters on the Call command line are allocated to the
  1738.    Passed-Parameters Variables in the Called Script in the same sequence
  1739.    they are written.  The first parameter goes into %1, the second into %2
  1740.    and so on.
  1741.  
  1742.    You might see why the numeric Variables are called Passed-Parameters.
  1743.    In the example above I had only one parameter ("Tony") but you can have
  1744.    up to nine of them, separated by commas.  If we had this Call command:
  1745.  
  1746.          C SUBS,Tony,VK2DHU,Port Macquarie,Australia
  1747.  
  1748.    then the Variables %1, %2, %3 and %4 would be filled and accessible
  1749.    from within the SUBS Script.  For example, %3 would contain the string
  1750.    "Port Macquarie".
  1751.  
  1752.    If you are observant, you will have noticed we are unable to include a
  1753.    comma as part of a parameter because it is used as a delimiter to
  1754.    separate the parameters.  Yeah, OK you got me there!  Sorry about that,
  1755.    but it is true.  You can't have a comma in a parameter!  Maybe in paKet
  1756.    version 97.2?
  1757.  
  1758.    While I am dealing with you observant ones, why do we have ten
  1759.    Passed-Parameters and only nine available on the command line?
  1760.    Time's up!   The first one, %0, always contains the name of the Script
  1761.    file currently running.  It doesn't matter whether we are using Called
  1762.    Scripts or not, you can always specify %0 in any Script and it will
  1763.    contain the name of THIS Script that is currently running.
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.                                Page 272
  1792.  
  1793. Script Tutorial - Scope of Variables
  1794.  
  1795.    The ordinary Variables are considered Global in scope which means you
  1796.    can set a Variable in one Script and use that same variable in another
  1797.    Script in this run.   For example, if we have a MAIN Script as follows:
  1798.  
  1799.          M %A,Australia
  1800.          E We start with %A
  1801.          C SUBS
  1802.          E Back again and our variable now contains %A.
  1803.          .
  1804.  
  1805.    and our SUBS Script looks like:
  1806.  
  1807.          E In SUBS now... and A still has %A
  1808.          M %A,UK
  1809.          R
  1810.  
  1811.    When we run the MAIN Script, we will see the following Echoes on our
  1812.    screen:
  1813.  
  1814.          We start with Australia
  1815.          In SUBS now... and A still has Australia
  1816.          Back again and our variable now contains UK.
  1817.  
  1818.  
  1819.  
  1820.    The Passed-Parameters are different.  They are considered local and are
  1821.    not visible to other Scripts.  So %1 in the main Script will probably
  1822.    contain a different value to the %1 in a called Script.
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.                                Page 273
  1848.  
  1849. Script Tutorial - a breather...
  1850.  
  1851.    Whew!
  1852.  
  1853.    How's it going?
  1854.  
  1855.    If you have had some programming experience you might be finding this a
  1856.    bit easier than if you are new to computers.  But don't despair if you
  1857.    are finding this a bit heavy.  You can get a lot out of Scripts by
  1858.    using some of the simpler commands we covered early in this section of
  1859.    the Manual.
  1860.  
  1861.    The Called Scripts, the Variables, and other complexities can wait...
  1862.    or you can still make use of some "clever" Scripts written by someone
  1863.    else.
  1864.  
  1865.  
  1866.    But if you are still with me... there's more.  Oh yes, we're not
  1867.    finished with Scripts yet.
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.                                Page 274
  1904.  
  1905. Script Tutorial - the I command
  1906.  
  1907.    Wouldn't it be nice if we could get the Script to stop and allow us to
  1908.    enter some information at the time of RUNNING the Script, instead of
  1909.    having to edit the Script File every time we want to run it?
  1910.  
  1911.    Didn't I tell you about this one?  This is the Input command.
  1912.  
  1913.    There are two parameters to this command.  The syntax is:
  1914.          I variable,prompt_string
  1915.  
  1916.    For example:
  1917.  
  1918.          I %C,Enter the callsign of the station you want to call...
  1919.  
  1920.     when the Script comes to this command, a Message Window will pop up
  1921.     displaying our prompt:
  1922.  
  1923.          Enter the callsign of the station you want to call...
  1924.  
  1925.     and paKet will stop while you enter something on the input line.
  1926.     Press <Enter> to complete your data.  Whatever you typed (except the
  1927.     <Enter> - that is not included) will now be stored in that variable,
  1928.     %C in our example here.  The Script then continues from the next line.
  1929.  
  1930.  
  1931.  
  1932. Script Tutorial - the ? and J commands
  1933.  
  1934.    The "?" is a Query command and is used to compare two values.
  1935.  
  1936.    In most formal programming languages, there is an IF statement which
  1937.    might look something like "IF A > 99 THEN Do-something".  I would have
  1938.    liked to provide some better way to compare two values, but this "?"
  1939.    command is the best I could do in the time available.  Hey, this is
  1940.    just a Communications Program after all!
  1941.  
  1942.    Anyway, the Query command is used with similar syntax to the other
  1943.    Script commands:
  1944.          ? value1,value2
  1945.  
  1946.    For example:
  1947.          ? %A,Port Macquarie
  1948.          ? %Z, %2
  1949.          ? Paul,Tony      (Don't ask me why you would want to do this,
  1950.                            but at least the syntax is valid!)
  1951.  
  1952.    The comparison is a text comparison and once again it is not sensitive
  1953.    to the case.  So "Tony" and "tony" are considered equal. And "90" is
  1954.    higher than "100".   Eh?  90 is higher than 100?   Yep, when doing a
  1955.    text comparison it finds the first character, "9" higher than the "1"
  1956.    so it decides 90 is higher than 100!
  1957.  
  1958.  
  1959.                                Page 275
  1960.  
  1961.    Performing a Query command is only half the job.  We also need some way
  1962.    of acting on the result of that comparison.  So we have a Jump ("J")
  1963.    command.  Actually we have six Jump commands:
  1964.  
  1965.          JE    Jump if the two values are Equal
  1966.          JNE   Jump if the two values are Not Equal
  1967.          JL    Jump if the first value is Lower than the second
  1968.          JNL   Jump if the first value is Not Lower than the second
  1969.          JG    Jump if the first value is Greater than the second
  1970.          JNG   Jump if the first value is Not Greater than the second
  1971.  
  1972.    The Jump commands have one parameter, that is the Label we want to Jump
  1973.    to if that condition is satisfied.  So we could have:
  1974.          C SUBS
  1975.          ? %Z,0
  1976.          JE Success
  1977.          ? %z,5
  1978.          JG Big Score
  1979.          JE five
  1980.          .
  1981.          .
  1982.          :Success
  1983.          E The SUBS went OK because we got a zero return code
  1984.          .
  1985.          .
  1986.          :Big Score
  1987.          E SUBS returned a value over 5!
  1988.          .
  1989.          .
  1990.          :five
  1991.          E We got exactly 5 in the SUBS return code
  1992.          .
  1993.          .
  1994.  
  1995.  
  1996.    The Jump commands will act on the LAST Query to be performed.  It would
  1997.    be the norm to issue a "?" command immediately prior to the Jump.  But
  1998.    if you forget to do the Query, paKet is quite happy to continue.  It
  1999.    will use the result of the last Query you did, no matter how long ago
  2000.    that was.  If there have been no Queries at all in this Script, paKet
  2001.    will consider the "result" to be Equal!
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.                                Page 276
  2016.  
  2017. Script Tutorial - the L, P and X commands
  2018.  
  2019.    I almost forgot these.
  2020.  
  2021.    But these simple commands are so simple it won't take long to explain
  2022.    them ALL!
  2023.  
  2024.    They are all single letter commands - no parameters on any of them.
  2025.  
  2026.  
  2027.    The L command toggles the Disk Log file on or off.  If it was on, this
  2028.    command will turn it off;  if it was off, this command will turn it on
  2029.    (using the default Log File name).
  2030.  
  2031.    The P command toggles the Printer Log on or off.  If it was on, this
  2032.    comm... (yes, yes, alright.  I know you know!)
  2033.  
  2034.    The X command is different and one that I sometimes think you should
  2035.    not have at all.  But someone asked for it, so it is still here.  This
  2036.    one will exit the paKet system altogether, returning us to the DOS
  2037.    Operating System (or to Windows or OS/2 or wherever we came from).  It
  2038.    is even more drastic than the <Alt-X>  (or the <Alt-F4>) command.  At
  2039.    least with those, you are asked "Are you sure?".  The X command does
  2040.    not give you a second chance.  So please use this one only if you are
  2041.    really sure you need it.
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.    Well, that's it!   Now we have covered all the Script commands.
  2054.    And now it's over to you to see what you can do with it all.  Try some
  2055.    simple ones to start with and build on them.  Discuss them with other
  2056.    paKet users on air and swap those you are satisfied with.  We can
  2057.    always learn from each other.
  2058.  
  2059.    I would be interested to hear of any ideas you have and to see the
  2060.    fruits of your Scripting labours.
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.                                Page 277
  2072.  
  2073. The Script File syntax.
  2074.  
  2075.   The rules:-
  2076.  
  2077.       1. The Script file is plain ASCII text
  2078.          (Extended ASCII graphic characters > $128 allowed).
  2079.  
  2080.       2. All lines must be less than 80 characters.
  2081.  
  2082.       3. Each Script file is limited to a maximum of 200 lines.
  2083.          (Use the CALL command to CALL other Scripts if you need more).
  2084.  
  2085.  All spaces will be ignored, except for EMBEDDED spaces in "text strings"
  2086.  (eg: in the Send command - LEADING spaces in "text" will be ignored). For
  2087.  example:
  2088.  
  2089.       s YU PROG.EXE
  2090.       W 10, Ready to Receive with YAPP protocol
  2091.       g not ready
  2092.       y u prog.exe
  2093.  
  2094.  is identical to:
  2095.  
  2096.       SYU PROG.EXE
  2097.       W10,Ready to Receive with YAPP protocol
  2098.       GNOT READY
  2099.       YUPROG.EXE
  2100.  
  2101.  
  2102.  You are the "programmer" here so choose a style that suits you best.
  2103.  Most people would find the latter example more difficult to read.  The
  2104.  careful use of spaces makes for more easily understood programming, which
  2105.  probably means fewer logic problems in your Scripts.
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.  
  2120.  
  2121.  
  2122.  
  2123.  
  2124.  
  2125.  
  2126.  
  2127.                                Page 278
  2128.  
  2129. Script Command Summary
  2130.  
  2131.    The following Script commands are valid:
  2132.  
  2133.    ! dos_command      Run a DOS command.
  2134.                       This will load a copy of COMMAND.COM and will pass
  2135.                       'dos_command' to DOS for processing. When that DOS
  2136.                       command/program has finished, processing of the
  2137.                       Script will continue from the next line in the
  2138.                       Script.
  2139.  
  2140.                       The comments I made for the <F9> key and for the
  2141.                       <Alt-E> in the "Keyboard Commands" section of this
  2142.                       Manual apply here too. You will not have the usual
  2143.                       amount of memory available for these DOS commands
  2144.                       because paKet is still running and still occupying a
  2145.                       lot of memory.
  2146.  
  2147.  
  2148.    *                  This is a comment line if it begins with an "*".
  2149.                       The rest of the line may contain anything at all
  2150.                       because a comment line is not loaded by the Script
  2151.                       processing.  It is used entirely as documentation in
  2152.                       your Script File on disk.
  2153.  
  2154.                       I strongly recommend the generous use of comments
  2155.                       in your Scripts.  If nothing else, writing comments
  2156.                       helps you to focus your mind on your own logic.
  2157.  
  2158.  
  2159.    : label            No processing is performed on this line.
  2160.                       It is used by the Goto, Trap and Jump commands.
  2161.  
  2162.                       As no processing is performed here, this could also
  2163.                       be used as a comment in your Script file.  But in
  2164.                       this case it IS loaded into memory with your Script.
  2165.                       If you intend this to be a comment only and not a
  2166.                       Label, it would be better to use the "*".
  2167.  
  2168.                       "label" may be any length but the total line length
  2169.                       must be less than 80 chars.
  2170.  
  2171.    ? value1,value2    Query command to compare two values.
  2172.                       This command compares the contents of the first
  2173.                       value with the contents of the second value.
  2174.                       The value fields may be Variables or constants.
  2175.  
  2176.                       This comparison is used together with one or more
  2177.                       Jump commands to provide some decision making
  2178.                       capability in a paKet Script.
  2179.  
  2180.  
  2181.  
  2182.  
  2183.                                Page 279
  2184.  
  2185.    AC                 Close the Download file.
  2186.                       Presumably this will follow the AD command somewhere
  2187.                       in your Script?
  2188.  
  2189.                       If the file is already closed, this command will be
  2190.                       ignored.
  2191.  
  2192.    AD filename        ASCII File download
  2193.                       (Same as <F6> but you must put filename on the
  2194.                       Script command line. (Eg: AD RECVFILE.DAT)  Note
  2195.                       that like <F6> if the file already exists, a new one
  2196.                       will be created with a sequential numeric extension
  2197.                       (RECVFILE.000 or RECVFILE.001 etc).
  2198.  
  2199.  
  2200.    AU filename        ASCII file Upload.
  2201.                       Same as <F5> but again you specify the filename in
  2202.                       the Script command line. (Eg: AU SENDFILE.DAT).
  2203.  
  2204.  
  2205.    B                  Send a BREAK code to the Serial Port. (Same as
  2206.                       <Alt-B> - return to cmd: mode)
  2207.  
  2208.  
  2209.    C script,p1,p2,... Call another Script, with optional parameters.
  2210.                       A Script file is limited to a maximum of 200 lines,
  2211.                       but if you find this limiting your style, you can
  2212.                       set up a number of Scripts and Call them as
  2213.                       required.
  2214.  
  2215.                       There is no practical limit to the number of nested
  2216.                       Scripts you may call. Each of the called Scripts
  2217.                       should "Return" to the calling Script, where
  2218.                       processing continues from the line following the
  2219.                       Call command.
  2220.  
  2221.                       Note the facility for Variables, Return Codes and
  2222.                       Flags to return the status of important events while
  2223.                       in the called Script.
  2224.  
  2225.                       If you want to pass some parameters to the called
  2226.                       Script, those parameters may be entered on the
  2227.                       command line.  The parameters are separated by a
  2228.                       comma.  Up to nine parameters may be specified.
  2229.  
  2230.  
  2231.    D time             Delay for "time" seconds, or delay until hh:mm.
  2232.      or               "time" may be 1 to 32767 seconds (about 9 hours).
  2233.    D hh:mm            "hh:mm" is a time of day.
  2234.  
  2235.                       If this time-of-day format is used, paKet will wait
  2236.                       until that time occurs before continuing.  Note, if
  2237.                       this time is earlier than the current time, paKet
  2238.                       will wait until that time TOMORROW before continuing.
  2239.                                Page 280
  2240.  
  2241.  
  2242.    E text             Echo text to the screen.
  2243.                       This is included mainly as a form of documentation
  2244.                       within the Script. The text is echoed to the screen
  2245.                       as if it was received from the other station, so it
  2246.                       will appear in your log file if it is active.
  2247.  
  2248.  
  2249.    FC n               Flag Clear
  2250.    FS n               Flag Set
  2251.    FT n               Flag Test
  2252.                       There are 10 flags available within the Script
  2253.                       system.
  2254.  
  2255.                       These are Binary flags (i.e either ON or OFF)
  2256.                       numbered 0 through to 9 and may be used by the
  2257.                       Script Programmer (that's YOU).
  2258.  
  2259.                       It was found by a paKet/Script user that there are
  2260.                       times when you need to remember the status of some
  2261.                       condition during the Script process.  By setting one
  2262.                       (or more) of the flags you can test the status of
  2263.                       that flag later in the Script and adjust the
  2264.                       processing as required.
  2265.  
  2266.                       For example you might need to note the fact that a
  2267.                       particular string was received from the TNC (using
  2268.                       the "W" command). When that string was received you
  2269.                       could Set a flag with the Flag Set Command,
  2270.                       (eg) "FS 4".
  2271.  
  2272.                       Later during this Script you could check the status
  2273.                       of that flag with the Flag Test command (eg) "FT 4".
  2274.                       If the flag is set, the next Script command is
  2275.                       performed, but if the tested flag is not Set (or
  2276.                       Clear) the next line in the Script is skipped.
  2277.  
  2278.                       With the introduction of Variables in paKet 6, we
  2279.                       have an alternative.  Instead of using a Flag, we
  2280.                       could Move some value into a Variable and Query that
  2281.                       Variable later.
  2282.  
  2283.                       You are the programmer, you make your choice!
  2284.  
  2285.  
  2286.    G label            Goto "label" and continue the Script from there.
  2287.                       (Yeah, yeah I know Goto is unfashionable!)
  2288.  
  2289.  
  2290.    I var,prompt       Input a string into a Variable.
  2291.                       paKet will display the prompt string in a Message
  2292.                       Window while waiting for you to enter some data
  2293.                       which will be stored in the specified Variable.
  2294.  
  2295.                                Page 281
  2296.  
  2297. Script Command Summary (cont)
  2298.  
  2299.    JE  label          These Jump commands will Jump to the Label specified
  2300.    JNE label          here, depending on the result of the previous Query
  2301.    JL  label          ("?" command).
  2302.    JNL label
  2303.    JG  label
  2304.    JNG label
  2305.  
  2306.  
  2307.    L                  Disk Log File On/Off toggle
  2308.                       This uses the default log filename.
  2309.  
  2310.  
  2311.    M var,text         Move data into a Variable.
  2312.                       The data is always taken as ASCII text data, even if
  2313.                       numeric strings are entered.
  2314.  
  2315.  
  2316.    P                  Printer Log On/Off toggle.
  2317.  
  2318.  
  2319.    Q                  Quit.
  2320.                       The Script processing is terminated. This would be
  2321.                       used for an aborted exit.
  2322.  
  2323.                       If we are using nested Scripts and the Quit is
  2324.                       performed in a Called Script, the entire chain is
  2325.                       aborted and control returns directly to paKet.
  2326.  
  2327.                       The Return command is a tidier way to exit a Script.
  2328.  
  2329.  
  2330.    R (return code)    Return with an optional Return Code.
  2331.                       This command is especially used to return control to
  2332.                       a calling Script. If used in the first level, or
  2333.                       only Script, Script processing is terminated and
  2334.                       control is returned to paKet.
  2335.  
  2336.                       The optional Return Code can be used to send back
  2337.                       results of this Script.
  2338.  
  2339.                       A Return will be assumed at the end of a Script file.
  2340.  
  2341.  
  2342.    S text             Send "text" to the TNC.
  2343.                       If you want to include a Control character such as
  2344.                       <Ctrl-C>, or an <Alt- > key combination such as
  2345.                       <Alt-A>, refer to the Special Key Codes section of
  2346.                       this Manual for the special syntax. Do not enter
  2347.                       quotes unless you want them sent to the TNC.
  2348.  
  2349.  
  2350.  
  2351.                                Page 282
  2352.  
  2353.                       You can also use substitution parameters such as $t
  2354.                       which will be replaced by the current time.  See the
  2355.                       Special Key Codes section of this Manual for details.
  2356.  
  2357.                       You can use any of the Script Variables here too.
  2358.  
  2359.                       A Carriage Return is generated automatically when
  2360.                       "text" has been sent. Note, if you do not want the
  2361.                       <CR> to be sent, add a caret ('^') as the last
  2362.                       character of the text.  paKet will then NOT generate
  2363.                       the <CR>. (It won't send that final caret either!)
  2364.  
  2365.  
  2366.    T label,string     Trap -  Goto 'label' if 'string' is received.
  2367.  
  2368.                       If 'string' is received at any time during this
  2369.                       Script, processing will continue from the nominated
  2370.                       'label'.  Note that this happens even if a "Delay"
  2371.                       or "Wait" instruction is in progress.
  2372.  
  2373.                       For example, say your Script includes the following
  2374.                       commands:
  2375.                          T MSG,Message waiting
  2376.                          T DONE,No Messages Available
  2377.  
  2378.                       Then, if the string "Message waiting" is received
  2379.                       from the TNC at any time during the processing of
  2380.                       this Script, paKet will detect the matching Trap
  2381.                       string and will continue processing from the MSG
  2382.                       label.
  2383.  
  2384.                       And if the string "No Messages Available" is
  2385.                       received at any time during the Script, processing
  2386.                       continues from the DONE label.
  2387.  
  2388.                       The Trap remains set even if nested Scripts are
  2389.                       CALLed, so 'label' must be a defined label within
  2390.                       all Scripts if the Trap is to be effective.
  2391.  
  2392.                       If a Trap is no longer required, it may be disabled
  2393.                       by specifying the command without a string. Eg:
  2394.                          T DONE,
  2395.                       (Note the comma is still required here).
  2396.  
  2397.                       Up to 30 Trap strings may be current at any one time.
  2398.  
  2399.  
  2400.    W time,string      Wait up to "time" seconds for "string" to be
  2401.                       received from the TNC.
  2402.  
  2403.                       The received "string" need not start at the
  2404.                       beginning of the line.
  2405.  
  2406.  
  2407.                                Page 283
  2408.  
  2409.                       If "string" is received within the specified "time"
  2410.                       the next line of the Script file is skipped,
  2411.                       otherwise the next line is executed.
  2412.  
  2413.                       Do not enter quotes in "string" unless you are
  2414.                       expecting them in the received text.
  2415.  
  2416.                       If no string is entered, (eg: W 60, ) paKet will
  2417.                       wait up to the time specified but the Wait is
  2418.                       considered satisfied as soon as ANYTHING is received!
  2419.  
  2420.  
  2421.    X                  Exit the paKet program.
  2422.                       This should be used with care. It will not only shut
  2423.                       down the Script, it will also shut down the paKet
  2424.                       program and will return to DOS.
  2425.  
  2426.  
  2427.    YD                 Commence a Binary File download.
  2428.                       This assumes the other station is now waiting to
  2429.                       send a Binary File to us with either pP or YAPP
  2430.                       protocol.
  2431.  
  2432.  
  2433.    YU filename        Commence a Binary File upload.
  2434.                       This assumes the other station is now waiting to
  2435.                       receive a file with either pP or YAPP protocol.
  2436.  
  2437.                       'filename' must include full path details unless it
  2438.                       is in the current directory.
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448.  
  2449.  
  2450.  
  2451.  
  2452.  
  2453.  
  2454.  
  2455.  
  2456.  
  2457.  
  2458.  
  2459.  
  2460.  
  2461.  
  2462.  
  2463.                                Page 284
  2464.  
  2465.